import urllib.request


def load_baidu():
    url = "http://www.baidu.com/"

    # 创建请求对象
    request = urllib.request.Request(url)
    # headers

    # 请求网络数据
    response = urllib.request.urlopen(request)
    data = response.read().decode('utf-8')

    # 响应头
    # print(response.headers)

    # 获取请求头的信息
    print(request.headers)
    with open('02header.html', mode='w', encoding='utf-8') as f:
        f.write(data)


load_baidu()
